import cv2
import numpy as np

# 0=IMREAD_GRAYSCALE灰度，1=IMREAD_COLOR彩色
img = cv2.imread("d:\\test\\test.jpg", cv2.IMREAD_GRAYSCALE)

# cv2.namedWindow('wl', cv2.WINDOW_AUTOSIZE)
# cv2.imshow('wl', img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

cv2.imshow('image', img)
k = cv2.waitKey(0) & 0xFF
if k == 27:
    cv2.destroyAllWindows()
elif k == ord('s'):
    cv2.imwrite('d:\\test\\test_gray.png', img)
    cv2.destroyAllWindows()
